package com.tanhua.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.mapper.BlacklistMapper;
import com.tanhua.sso.pojo.BlackList;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlacklistServiceApiImpi implements BlacklistServiceApi{

    @Autowired
    private BlacklistMapper blacklistMapper;

    //分页查看黑名单
    @Override
    public Page<BlackList> page(Long userId, Integer page, Integer pagesize) {
        Page<BlackList> blackListPage=new Page<>(page,pagesize);
        LambdaQueryWrapper<BlackList> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ObjectUtil.isNotEmpty(userId),BlackList::getUserId,userId).orderByDesc(BlackList::getUpdated);
        blacklistMapper.selectPage(blackListPage,lambdaQueryWrapper);
        return blackListPage;
    }

    //移除黑名单
    @Override
    public void delectBlackList(Long userId, Long uid) {
        LambdaQueryWrapper<BlackList> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ObjectUtil.isNotEmpty(userId),BlackList::getUserId,userId).eq(ObjectUtil.isNotEmpty(uid),BlackList::getBlackUserId,uid);
        blacklistMapper.delete(lambdaQueryWrapper);
    }
}
